#define _CRT_SECURE_NO_WARNINGS 1

//#include "ObjectPool.h"
#include "ConcurrentAlloc.h"
#include "Common.h"
#include "ObjectPool.h"
#include <cstdlib>
#include <time.h>


//int main()
//{
//	ObjectPool<TreeNode> op;
//	TreeNode* node = op.New();
//	cout << node->_val << endl;
//	op.Delete(node);
//	return 0;
//}

//int main()
//{
//	TestObjectPool();
//
//	return 0;
//}


//void Alloc1()
//{
//	for (size_t i = 0; i < 5; ++i)
//	{
//		void* ptr = ConcurrentAlloc(6);
//	}
//}
//
//void Alloc2()
//{
//	for (size_t i = 0; i < 5; ++i)
//	{
//		void* ptr = ConcurrentAlloc(18);
//	}
//}
//
//
//void TLSTest()
//{
//	std::thread t1(Alloc1);
//	t1.join();
//
//	std::thread t2(Alloc2);
//	t2.join();
//}
//
//int main()
//{
//	//TestObjectPool();
//	TLSTest();
//
//	return 0;
//}

void HahaTest()
{
	void* p1 = ConcurrentAlloc(5);
	cout << p1 << endl;
	void* p2 = ConcurrentAlloc(1);
	cout << p2 << endl;
	void* p3 = ConcurrentAlloc(3);
	cout << p3 << endl;
	void* p4 = ConcurrentAlloc(6);
	cout << p4 << endl;
	void* p5 = ConcurrentAlloc(8);
	cout << p5 << endl;
	void* p6 = ConcurrentAlloc(2);
	cout << p6 << endl;
	void* p7 = ConcurrentAlloc(2);
	cout << p7 << endl;
}

void LalaTest()
{
	for (size_t i = 0; i < 1024; ++i)
	{
		void* p1 = ConcurrentAlloc(6);
		cout << p1 << endl;
	}

	void* p2 = ConcurrentAlloc(8);
	cout << p2 << endl;
}

void MultiThreadAlloc1()
{
	std::vector<void*> v;
	for (size_t i = 0; i < 100; ++i)
	{
        void* ptr = ConcurrentAlloc(5);
		v.push_back(ptr);
 	}

	for (auto i : v)
	{
		cout << i << endl;
		ConcurrentFree(i);
	}
	cout << "=======================================" << endl;
	for (size_t i = 0; i < 100; ++i)
	{
		void* ptr = ConcurrentAlloc(5);
		v[i] = ptr;
	}

	for (auto i : v)
	{
		cout << i << endl;
		ConcurrentFree(i);
	}
}

void TestConcurrentAlloc2()
{
	void* p1 = ConcurrentAlloc(6);
	void* p2 = ConcurrentAlloc(8);
	void* p3 = ConcurrentAlloc(1111);
	void* p4 = ConcurrentAlloc(71);
	void* p5 = ConcurrentAlloc(8);
	void* p6 = ConcurrentAlloc(68);
	void* p7 = ConcurrentAlloc(8);
	void* p8 = ConcurrentAlloc(1111);


	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	cout << p5 << endl;
	cout << p6 << endl;
	cout << p7 << endl;
	cout << p8 << endl;


	ConcurrentFree(p1);
	ConcurrentFree(p2);
	ConcurrentFree(p3);
	ConcurrentFree(p4);
	ConcurrentFree(p5);
	ConcurrentFree(p6);
	ConcurrentFree(p7);
	ConcurrentFree(p8);

}

void TestConcurrentAlloc3()
{
	void* p1 = ConcurrentAlloc(6);
	void* p2 = ConcurrentAlloc(8);
	void* p3 = ConcurrentAlloc(MAX_BYTES + 3);
	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;

	ConcurrentFree(p1);
	ConcurrentFree(p2);
	ConcurrentFree(p3);

}



//int main()
//{
//	//srand(time(nullptr));
//	MultiThreadAlloc1();
//	return 0;
//}




//int main()
//{
//	TestObjectPool();
//
//	return 0;
//}